package ControlLayer;
import ModelLayer.*;
import DBLayer.*;

import java.util.ArrayList;
/**
 *
 * @author Pavel
 */
public class ProductCtr {
    public ProductCtr(){

    }

    public ArrayList<Product> findAllProducts(){
        IFDBProduct dbProduct = new DBProduct();
        ArrayList allProducts = new ArrayList();
        allProducts = dbProduct.getAllProducts();
        return allProducts;
    }

    public Product getById(int id){
        IFDBProduct dbProduct = new DBProduct();
        return dbProduct.searchById(id);
    }

    public Product getByName(String name){
        IFDBProduct dbProduct = new DBProduct();
        return dbProduct.searchByName(name);
    }

    public ArrayList<Product> getBySupplierId(int id){
        IFDBProduct dbProduct = new DBProduct();
        return dbProduct.searchBySupplierId(id);
    }

    public ArrayList<Product> getByCountry(String country){
        IFDBProduct dbProduct = new DBProduct();
        return dbProduct.searchByCountry(country);
    }

    public int updateProduct(String name, float purchase_price, float sale_price, float rent_price, int min_stock){
        IFDBProduct dbProduct = new DBProduct();
        Product product = new Product();
        product.setName(name);
        product.setPurchasePrice(purchase_price);
        product.setSalesPrice(sale_price);
        product.setRentPrice(rent_price);
        product.setMinStock(min_stock);
        return dbProduct.updateProduct(product);
    }

    public void insertProduct(Product prodObj){
        IFDBProduct dbProd = new DBProduct();
        dbProd.insertProduct(prodObj);
    }

    public void deleteProduct(int id){
        IFDBProduct dbProd = new DBProduct();
        dbProd.deleteProduct(id);
    }

}
